/*
 * This program is free software; you can redistribute it and/or modify 
 * it under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; either version 3 of the License, or 
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
 * for more details.
 * 
 * You should have received a copy of the GNU General Public License along 
 * with this program; if not, write to the Free Software Foundation, Inc., 
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#ifndef WISHMASTER_CHANMANAGER_H
#define WISHMASTER_CHANMANAGER_H

#include <QObject>
#include "components/chan.h"
#include "threadstorage.h"
#include "components/thread.h"
#include "components/boardconstraints.h"
#include "keymapmanager.h"
#include "filterlist.h"
#include "chanlist.h"
#include "misc.h"
#include "chanagents/agentfactory.h"
#include "requestmanager.h"

class ImageViewForm;
class MainWindow;
namespace Wishmaster
{
	class Extractor;
	class MainWindowDirector;
	class Taskhub;
	class ChanWatcher;
	class WISHMASTER_EXPORT ChanManager : public QObject
	{
		Q_OBJECT
	public:
		virtual ~ChanManager() {}

		virtual bool initialize() = 0;
		virtual bool shutdown() = 0;

		virtual void setImageView(ImageViewForm* imageview) = 0;

		virtual bool requestFavicon(const QString& chanName) = 0;
		virtual bool requestBoardIndex(const QString& chanName, const QString& boardId, int page) = 0;
		virtual bool requestThread(const ThreadId& threadId) = 0;
		virtual bool requestThumbnail(const PostId& postId, int attachmentIndex, const QUrl& url) = 0;
		virtual bool requestPic(const PostId& postId, int attachmentIndex) = 0;
		virtual bool downloadFile(const PostId& postId, int attachmentIndex, const QString& filename) = 0;
		virtual bool requestCaptcha(const ThreadId& threadId) = 0;
		virtual bool addPost(const ThreadId& threadId, const PostDescriptor& post, const QString& captcha) = 0;
		virtual bool createThread(const QString& chanName, const QString& boardId, const PostDescriptor& post, const QString& captcha) = 0;

		virtual void setFilterList(const FilterListPtr& list) = 0;
		virtual FilterListPtr filterList() const = 0;

		virtual void refresh(bool ignoreOverrides, bool indexOnly) = 0;
		virtual void updateContent(const QString& chanName, const QString& boardId) = 0;
		virtual void updateContent(const PostId& postId, int attachmentIndex) = 0;
		virtual void collectGarbage() = 0;
		virtual void updateAttachment(const PostId& postId, int attachmentIndex) = 0;

		virtual void showPicture(const PostId& postId, int attachmentIndex) = 0;

		virtual bool loadChanList(const QString& filename, AgentFactory* agentFactory) = 0;
		virtual bool loadChanList(const QByteArray& data, AgentFactory* agentFactory) = 0;

		//virtual void updateFavicons() = 0;

		virtual FilterListPtr globalFilterList() = 0;

		virtual void setChanlistFilename(const QString& filename) = 0;

		virtual Taskhub* taskhub() = 0;
		virtual Connector* connector() = 0;
		virtual ChanList* chanlist() const = 0;
		virtual ChanWatcher* chanwatcher() const = 0;

		virtual void setThreadStorage(ThreadStorage* storage) = 0;
		virtual ThreadStorage* threadStorage() const = 0;

		virtual Wishmaster2::Network::RequestManager* requestManager() const = 0;

		static const int ThreadIdRole = Qt::UserRole + 1;

	signals:
		void boardListChanged(const QStringList& boardlist);
		void chanListChanged(const QStringList& chanlist);
		void contentChanged(const QString& chanName, const QString& boardId);
		void contentChanged(const PostId& postId, int attachmentIndex);
		void attachmentUpdated(const PostId& postId, int attachmentIndex);
		void captcha(const ThreadId& threadId, const QByteArray& data);
		void statusMessage(const QString& msg, int timeout = 0);

	public slots:
		virtual void swap() = 0;
		virtual void newMessages(const PostId& thread) = 0;
	};
}

#endif

